//
//  IMMessageReceiveCell.m
//  WeiYiMei
//
//  Created by iMac on 2019/5/7.
//  Copyright © 2019年 liyefu. All rights reserved.
//

#import "IMMessageReceiveCell.h"

@interface IMMessageReceiveCell ()

@property (nonatomic, strong) UIImageView *icon;
//@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UIView *messageContentView;
@property (nonatomic, strong) UILabel *messageLab;
@property (nonatomic, strong) UILabel *dtLabel;

@end

@implementation IMMessageReceiveCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupSubViews];
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

- (void)setMessage:(IMMessageEntity *)message
{
    _message = message;
    self.messageLab.text = message.content;
    self.dtLabel.text = message.dt;
    
}

- (void)setupSubViews
{
    [self.contentView addSubview:self.icon];
//    [self addSubview:self.nameLab];
    [self.contentView addSubview:self.messageContentView];
    [self.messageContentView addSubview:self.messageLab];
    [self.contentView addSubview:self.dtLabel];
    
    self.messageLab.textColor = kColor333333;
    self.messageContentView.backgroundColor = [UIColor whiteColor];
    
    [self.dtLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView);
        make.left.right.equalTo(self.contentView);
    }];
    
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(kWidth(15));
        make.top.equalTo(self.dtLabel.mas_bottom).offset(kWidth(10));
        make.width.height.equalTo(@(kWidth(40)));
    }];
    
//    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.icon);
//        make.left.equalTo(self.icon.mas_right).offset(kWidth(6));
//    }];
    
    [self.messageContentView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.nameLab);
        make.left.equalTo(self.icon.mas_right).offset(kWidth(6));
//        make.top.equalTo(self.nameLab.mas_bottom).offset(kWidth(6));
        make.top.equalTo(self.icon);
        make.right.lessThanOrEqualTo(self.contentView).offset(-kWidth(kScreenW/4.0));
        make.bottom.equalTo(self.contentView);
    }];
    
    [self.messageLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self.messageContentView).offset(kWidth(10));
        make.bottom.right.equalTo(self.messageContentView).offset(-kWidth(10));
    }];
}

- (UIImageView *)icon
{
    if (!_icon) {
        _icon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"person_headpic"]];
        _icon.layer.cornerRadius = kWidth(20);
        _icon.layer.masksToBounds = YES;
        _icon.backgroundColor = [UIColor whiteColor];
    }
    return _icon;
}

//- (UILabel *)nameLab
//{
//    if (!_nameLab) {
//        _nameLab = [[UILabel alloc] init];
//        _nameLab.textColor = kColor666666;
//        _nameLab.font = [UIFont systemFontOfSize:12];
//    }
//    return _nameLab;
//}

- (UIView *)messageContentView
{
    if (!_messageContentView) {
        _messageContentView = [[UIView alloc] init];
    }
    return _messageContentView;
}

- (UILabel *)messageLab
{
    if (!_messageLab) {
        _messageLab = [[UILabel alloc] init];
        _messageLab.numberOfLines = 0;
        _messageLab.font = [UIFont systemFontOfSize:15];
    }
    return _messageLab;
}

- (UILabel *)dtLabel
{
    if (!_dtLabel) {
        _dtLabel = [[UILabel alloc] init];
        _dtLabel.textColor = kColorAAAAAA;
        _dtLabel.font = [UIFont systemFontOfSize:12];
        _dtLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _dtLabel;
}

@end
